package com.vpen.block.task;

import com.vpen.block.model.PlanDTO;
import com.vpen.block.queue.BlockQueuePlanBuff;
import com.vpen.block.queue.PlanBuff;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;



/**
 * @version: 1.0
 * @author: Vpen
 * @date: 2021/11/20 23:54
 * @content:
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ProducerAndConsumerService {
    private final ProducerPlan producerPlan;
    private final ConsumerPlan consumerPlan;

    private final ProducerPlan2 producerPlan2;
    private final ConsumerPlan2 consumerPlan2;

    private final PoolConfig poolConfig;
    private static final BlockQueuePlanBuff buff = new BlockQueuePlanBuff();
    private static final PlanBuff planBuff = new PlanBuff();

    /**
     * 开始任务
     *
     * @param plan plan
     * @return void
     * @author Vpen
     * @date 2021/11/21 11:59
     * @name startTask
     **/
    public void startTask(PlanDTO plan) {
        producerPlan.setBuff(buff);
        producerPlan.setPlan(plan);
        consumerPlan.setBuff(buff);
        poolConfig.startTask(producerPlan);
        poolConfig.startTask(consumerPlan);
    }

    /** 开始任务
     * @author Vpen
     * @date 2021/11/21 19:38
     * @name startTask2
     * @param plan plan
     * @return void
     **/
    public void startTask2(PlanDTO plan) {
        producerPlan2.setPlanBuff(planBuff);
        producerPlan2.savePlan(plan);

        consumerPlan2.setPlanBuff(planBuff);
        poolConfig.startTask(consumerPlan2);
    }
}

